package com.xsd.awen.config;

import com.xsd.awen.utils.GsonUtils;
import lombok.Data;

@Data
public class WebResult {

    private int code = 200;

    private String message;

    private Object data;

    private Long count;

    public WebResult() {
    }

    public WebResult(Object data) {
        this.data = data;
    }

    public static String OK(){
        return GsonUtils.toJson(new WebResult());
    }

    public static String ERROR(String message){
        return ERROR(-1,message);
    }

    public static String ERROR(int code,String message){
        WebResult wr = new WebResult();
        wr.setCode(code);
        wr.setMessage(message);
        return GsonUtils.toJson(wr);
    }

    public static String page(Object data,long count){
        WebResult wr = new WebResult(data);
        wr.setCode(0);
        wr.setCount(count);
        return GsonUtils.toJson(wr);
    }

    public static String page(Object data){
        WebResult wr = new WebResult(data);
        wr.setCode(0);
        return GsonUtils.toJson(wr);
    }

    public static String OK(Object data){
        return GsonUtils.toJson(new WebResult(data));
    }

}
